import { Sequelize } from 'sequelize';
import { join, resolve } from 'path';
import * as fs from 'fs';

export const initSqls = async (seq: Sequelize) => {
    try {
        const sql = fs.readFileSync(join(__dirname, '../../../sql/init.sql')).toString();
        const sqls = sql.split(';').filter(s => !!s.trim());
        
        await seq.transaction(async () => {
            for (let i = 0; i < sqls.length; i++) {
                await seq.query(sqls[i]);
            }
        })
    } catch (_) {
        console.log(_);
    }
};
